package han.cirno.corrupt.dialog

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.ViewGroup
import android.view.Window
import androidx.viewbinding.ViewBinding
import han.cirno.corrupt.R
import han.cirno.corrupt.util.DensityUtil

open class BottomPopDialog<VB : ViewBinding>(context: Context, protected val viewBinding: VB) : Dialog(context, R.style.BottomDialog) {
    init {
        init()
    }

    private fun init(){
        setContentView(viewBinding.root)
        val params:ViewGroup.MarginLayoutParams = viewBinding.root.layoutParams as ViewGroup.MarginLayoutParams
        params.width=context.resources.displayMetrics.widthPixels-DensityUtil.dp2px(16f)
        params.bottomMargin=DensityUtil.dp2px(8f)
        viewBinding.root.layoutParams=params
        val window:Window = window?:throw NullPointerException()
        window.setGravity(Gravity.BOTTOM)
        window.setWindowAnimations(R.style.BottomDialog_Animation)
    }
}